#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int romanToInt(char* s)
{
    int sum = 0;
    while (*s)
    {
        if (*s == 'M')
        {
            sum += 1000;
            s++;
            break;
        }
        if (*s == "D")
        {
            sum += 500;
            s++;
            break;
        }
        if (*s == 'C' && *(s + 1) != 0 && *(s + 1) != 'L' && *(s + 1) != 'X' && *(s + 1) != 'V' && *(s + 1) != 'I')
        {
            sum -= 100;
            while (*(s + 1) != 'D')
            {
                sum -= 100;
                s++;
            }
            break;
        }
        else if (*s == 'C')
        {
            sum += 100;
            s++;
            break;
        }
        if (*s == 'L')
        {
            sum += 50;
            s++;
            break;
        }
        if (*s == 'X' && *(s + 1) != 0 && *(s + 1) != 'I' && *(s + 1) != 'V' && *(s + 1) != 'I')
        {
            sum -= 10;
            while (*(s + 1) != 'C' && *(s + 1) != 'L')
            {
                sum -= 10;
                s++;
            }
            break;
        }
        else if (*s == 'X')
        {
            sum += 10;
            break;
        }
        if (*s == 'V')
        {
            sum += 5;
            s++;
            break;
        }
        if (*s == 'I' && *(s + 1) != 0 && *(s + 1) != 'I')
        {
            sum -= 1;
            while (*(s + 1) != 'V' && *(s + 1) != 'X')
            {
                sum -= 1;
                s++;
            }
            break;
        }
        else if (*s == 'I')
        {
            sum += 1;
            break;
        }
    }
    return sum;
}
int main()
{
    char str[20] = "III";
    printf("%d", romanToInt(str));
    return 0;
}